<div id="box-link" class="fLeft">
	<ul>
		<li class="link1"><a href="#">Tin tức</a></li>
		<li class="link2"><a href="#">Danh bạ</a></li>
		<li class="link3"><a href="#">Diễn đàn</a></li>
	</ul>
</div><!--End link-->
<div id="box-user" class="fLeft">
	<ul>
		<li class="login"><a href="#">Đăng kí</a></li>
		<li class="regest"><a href="#">Đăng nhập</a></li>
	</ul>
</div><!--End user-->
<div id="box-topmenu" class="fRight">
	<ul>
        <?php 
            $i = 0;
            $class = 'class="first"';
            foreach($topmenu as $tm){
                echo '<li '.($i == 0 ?$class:'').'><a href="'.base_url().$tm->alias.'.html">'.$tm->title.'</a></li>';
            $i++;
            }
        ?>
		<li><a class="modalbox" href="#inline">GÓP Ý</a></li>
		<li class="last"><a class="modalbox" href="#inline">LIÊN HỆ</a></li>
	</ul>
</div><!--End topmenu-->
<script type="text/javascript">
	function validateEmail(email) { 
		var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return reg.test(email);
	}

	$(document).ready(function() {
	   $('.modalbox').click(function(){
	      var title = $(this).text(); 
          $("#param").text(title);
	   });
		$(".modalbox").fancybox();
		$("#contact").submit(function() { return false; });
        
		$("#send").on("click", function(){
            
			var emailval  = $("#email").val();
            
            var nameval  = $("#name").val();
            var namelen    = nameval.length;
            
            var addressval  = $("#address").val();
            var addresslen    = addressval.length;
            
            var phoneval  = $("#phone").val();
            var phonelen    = phoneval.length;
            
			var contentval    = $("#content").val();
			var contentlen    = contentval.length;
			var mailvalid = validateEmail(emailval);
			var minlen = 6;
			if(mailvalid == false) {
				$("#email").addClass("error");
			}
			else if(mailvalid == true){
				$("#email").removeClass("error");
			}
			if(namelen < minlen) {
				$("#name").addClass("error");
			}else if(namelen >= minlen){
				$("#name").removeClass("error");
			}
            if(phonelen < minlen) {
				$("#phone").addClass("error");
			}else if(phonelen >= minlen){
				$("#phone").removeClass("error");
			}
            if(addresslen < minlen) {
				$("#address").addClass("error");
			}else if(addresslen >= minlen){
				$("#address").removeClass("error");
			}
            if(contentlen < minlen*5) {
				$("#content").addClass("error");
			}else if(contentlen >= minlen){
				$("#content").removeClass("error");
			}
			if(mailvalid == true && contentlen >= minlen*5 && namelen >=minlen && addresslen >=minlen && phonelen >=minlen) {
				
                $.ajax({
					type: 'POST',
					url: '<?php echo base_url();?>mod_topmenu/mod_topmenu/sendemail',
					data: $("#contact").serialize(),
					success: function(data) {
                        ketqua = data.substring(0,2)
                        messenger = data.substring(2)
						if(ketqua != "NO") {
							$("#contact").fadeOut("fast",  function(){
                                //$("#contactmessenger").css("display","block");
                                //$("#contactmessenger").html(messenger);
                                
                                setTimeout(function(){
                                    $("#contactmessenger").css("display","none");
                                    $("#contact").css("display","block");
                                }, 3000);
                                setTimeout("$.fancybox.close()", 3100);
							});
                        }
                            $("#contactmessenger").css("display","block");
                            $("#contactmessenger").html(messenger);
                        
					}
				});
			}
		});
	});
</script>


<div id="inline" style="z-index: 9999;">
	<h2 id="param">FORM LIÊN HỆ</h2>

	<form id="contact" name="contact" action="#" method="post">
		<label for="name">Họ tên:</label>
		<input type="name" id="name" name="name" class="txt">
		<br/>
        <label for="address">Địa chỉ:</label>
		<input type="address" id="address" name="address" class="txt">
		<br/>
        <label for="phone">Điện thoại:</label>
		<input type="phone" id="phone" name="phone" class="txt">
		<br/>
        <label for="email">Email</label>
		<input type="email" id="email" name="email" class="txt">
		<br/>
		<label for="content">Nội dung</label>
		<textarea id="content" name="content" class="txtarea"></textarea>
		
		<button id="send">Gửi góp ý</button>
	</form>
    <div id="contactmessenger"></div>
</div>